<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转回本金</title>
</head>
<body>
<div class="page">
    <div id="headerHtml">123</div>
    <script id="headerScript" type="text/html">
        {{each data item index}}
        {{if item.accountType==1}}
        <h3 class="big-title">{{item.accountType | accountType}}</h3>
                <div class="page-container">
                <h3 class="child-title">{{item.accountType | accountType}}:<span>{{item.amountNum}}</span></h3>

        </div>
        {{/if}}
        {{/each}}
    </script>
    <form action="" class="page-container" id="sub">
        <div class="inputs clearfloat">
            <label for="optionHtml" class="">转出账号</label>
            <select class="select" id="optionHtml" name="profitsAccountId">
                <script id="optionScript" type="text/html">
                    {{each data item index}}
                        {{if item.accountType != 0 && item.accountType != 2 && item.accountType % 10 < 5}}
                             <option value="{{item.id}}" data-accountType="{{item.accountType}}">{{item.accountType | accountType}}：{{item.amountNum}}</option>
                        {{/if}}
                    {{/each}}
                </script>
            </select>
        </div>
        <div class="inputs clearfloat">
            <label for="amount" class="">转出金额</label>
            <input type="text" name="amount" id="amount">
        </div>
        <div class="inputs clearfloat">
            <label for="payPassword" class="">支付密码</label>
            <input type="password" name="payPassword" id="payPassword">
        </div>

        <div class="edit">
            <input type="button" class="buttons" value="确认" id="zhbj">

        </div>
    </form>

</div>
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/layer/layer.js"></script>
<script src="js/moment-2.2.1.js"></script>
<script src="js/template-web.js"></script>
<script src="js/jdgj/config.js"></script>
<script>
    var userId = config.getUserId();
    // 加载账户信息信息
    template.defaults.imports.accountType = function(value){
        return config.accountType(value);
    };
    var pageNo = pageNo | 1;
    $.get(config.baseUrl + "/account/quaryAccount.json",{userId: userId }, function(result){
        if (result.status == 200) {
            var html1 = template("headerScript", result);
            $("#headerHtml").html(html1);

            var html = template("optionScript", result);
            $("#optionHtml").html(html);
        }
    });
    // 转回本金
    $("#zhbj").click(function (e) {
        e.preventDefault();
        var profitsAccountId = $("#profitsAccountId").val();
        var amount = $("#amount").val();
        var payPassword = $("#payPassword").val();
        if (profitsAccountId!='' && amount!='' && payPassword!='' ){
            // 验证支付密码
            $.get(config.baseUrl+"/user/validatorPayPassword.json", {userId:userId, payPassword: payPassword}, function(result){
                if(result.status == 200) {
                    $.post(config.baseUrl+"/account/profitsToCapital.json",{userId:userId, profitsAccountId:profitsAccountId, amount:amount}, function(result){
                        if(result.status == 200) {
                            layer.alert("转回成功");
                            $("#sub").reset();
                        } else {
                            layer.alert(result.msg);
                        }
                    },"json");
                } else {
                    layer.alert("支付密码错误");
                }
            }, "json")


        } else {
            layer.alert("所有字段都是必填项");
        }

    });

</script>
</body>
</html>